<template>
  <div class="about" ref="homePage">
    <div style="height: 60px;display: flex;align-items: center;position: fixed;width: 100%;background: #46d0ca;">
      <div class="search">
        <div @click="select" class="search_cs">
          <span>{{current}}</span>
          <van-icon name="arrow-down" />
        </div>
        <div class="search_in">
          <form action="/">
            <van-search placeholder="搜索想要的旅游产品或服务" v-model="search_value" @search="issuecontent" />
          </form>
        </div>
        <div id="container"></div>
        <!-- <div style="display: flex;align-items: center;">
          <van-icon name="search" color="#00CBA6" size="24" />
        </div> -->
      </div>
    </div>

    <!-- <p id='adcode'></p> -->
    <van-popup position="" style="width: 100%;height: 100%;" v-model="show">
      <van-nav-bar title="城市列表" left-arrow @click-left="onClickLeft" />
      <div style="width: 100%;height: 46px;"></div>
      <div class="current">
        <div class="current_box">
          <span>当前城市</span>
          <span style="color: #00CBA6;">{{current}}</span>
        </div>
        <div class="current_box">
          <span>定位城市</span>
          <span style="color: #00CBA6;display: flex;align-items: center;">
            <van-icon name="location" size="16px" />{{chengshi}}</span>
        </div>
      </div>
      <div class="popular">
        <p class="popular_p">热门城市</p>
        <div style="display: flex;flex-wrap: wrap;justify-content: space-around;">
          <div @click="popularCs(itme)" class="popular_cs" v-for="(itme,index) in Popular" :kye='index'>{{itme}}</div>
        </div>
      </div>
      <!-- <div> -->
      <van-index-bar :index-list="nameData">
        <div v-for="(data,index) in ityList" :key="index">
          <van-index-anchor :index="data.id">{{data.name}}</van-index-anchor>
          <van-cell @click="cell(res.name)" v-for="(res,index) in data.content" :key="index" :title="res.name" />

        </div>

      </van-index-bar>

    </van-popup>
    <div class="sort">
      <van-dropdown-menu active-color="#51c5b8" style="background: rgb(240, 240, 240);">
        <div style="width: 1px;height: 20px;border: 1px solid rgb(225, 225, 225);position: absolute;left: 51%;top: 10px;"></div>
        <van-dropdown-item style="" v-model="value1" :options="option1" @change="changeabout" />
        <van-dropdown-item v-model="value2" :options="option2">

        </van-dropdown-item>
      </van-dropdown-menu>
    </div>
    <!-- <v-sort class="vsort"></v-sort> -->
    <div style="width: 100%;height: 100px;"></div>
    <div>
      <div v-show="resdata.length == 0" class="wudingdan">
        <van-icon name="description" />
        <p>亲,暂无相关数据哦</p>
      </div>
      <div v-show="resdata.length != 0" class="about-box">
        <van-list style="flex-wrap: wrap;display: flex;justify-content: center;width: 100%;" v-model="loading" :finished="finished" finished-text="没有更多了······" @load="onLoad">
          <div style="flex-wrap: wrap;display: flex;width: 100%;">
            <div class="content-piece" @click="routersoeciakty(itme.resSN)" v-for="(itme,index) in resdata" :key='index'>
              <div class="piece-img">
                <img :src="itme.Cover" />
              </div>
              <div class="piece-size">
                <span>{{itme.Name}}</span>
              </div>
              <div class="piece-money">
                <div>
                  <div style="color: #8f8f8f;">¥<span style="color: #68C5BA;font-size: 20px;display: inline-block;text-align: center;">{{itme.Price}}</span>元</div>
                  <div><span>{{itme.SaleNum}}</span>人付款</div>
                </div>
                <div style="text-align: right;font-size: 12px;">
                  <div>原地产：{{itme.City}}</div>
                  <span style="font-size: 24px;color: #68C5BA;">...</span>
                </div>

              </div>

            </div>
          </div>
        </van-list>
        <div style="height: 50px;width: 100%;"></div>
      </div>
    </div>

    <v-min></v-min>
  </div>

</template>
<script>
// @ is an alias to /src
// import searche from '../components/searche.vue';
// import sort from '../components/sort.vue';
// import min from '../views/Min.vue'
import city from '@/assets/js/city.js'
import AMap from "AMap"
import min from '@/views/Min.vue'
import {
  resourceList
} from '@/api/home.js'
export default {
  // name: 'about',
  components: {
    "v-min": min,
  },
  data () {
    return {
      show: false,
      chengshi: '', //定位
      current: '', //选择城市
      search_value: '',
      nameData: [
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
        'W',
        'X', 'Y', 'Z'
      ],
      Popular: ['上海', '北京', '广州', '深圳', '武汉', '天津', '西安', '南京', '杭州', '成都', '重庆', '郑州'],
      ityList: city, //城市数组

      //头部以 下
      value1: 1,
      value2: 1,
      option1: [{
        text: '综合',
        value: 1
      },
      {
        text: '价格降序',
        value: 2
      },
      {
        text: '价格升序',
        value: 3
      }
      ],
      option2: [{
        text: '推荐排序',
        value: 1
      },
      {
        text: '销量火爆',
        value: 2
      },

      ],
      result: [],
      checked: false,
      isDisabled: false,

      clintHeigth: '', //获取页面高度
      // name:'',
      // phone:'',
      // card:'',
      // tanchu:false,
      resdata: [],
      loading: false, //控制上拉加载的加载动画
      finished: false, //控制在页面往下移动到底部时是否调用接口获取数据
      PageCount: 0,
      pageNumber: 0, //自定义一个变量
    }
  },
  mounted () {
    this.onLoad()
    this.clientHeight = `${document.documentElement.clientHeight}` //document.body.clientWidth;
    // console.log(this.clientHeight);
    // let dd = 100;
    this.$refs.homePage.style.minHeight = this.clientHeight + 'px';
    if (sessionStorage.getItem("city")) {
      this.current = sessionStorage.getItem("city")
    } else {
      this.mapinit()
    }
  },
  methods: { //点击事件
    mapinit () { //定位
      let that = this
      let map = new AMap.Map("container", {
        enableHighAccuracy: true,

        resizeEnable: true,
        center: [114.085947, 22.547],
        zoom: 8,
      });
      // document.getElementById('adcode').innerHTML = '当前城市adcode：' + map.getAdcode() + '<br>' +
      //   '当前中心点：' + map.getCenter()
      //获取用户所在城市信息
      function showCityInfo () {
        //实例化城市查询类
        let citysearch = new AMap.CitySearch();
        //自动获取用户IP，返回当前城市
        citysearch.getLocalCity(function (status, result) {
          // console.log(result)
          if (status === 'complete' && result.info === 'OK') {

            if (result && result.city && result.bounds) {
              // console.log(JSON.stringify(result));
              let cityinfo = result.city;
              let citybounds = result.bounds;
              that.chengshi = cityinfo
              that.current = cityinfo
              // document.getElementById('info').innerHTML = '您当前所在城市：' + cityinfo;
              //地图显示当前城市
              map.setBounds(citybounds);
            }
          } else {
            // document.getElementById('info').innerHTML = result.info;
            // console.log(result)
          }
        });
      }
      showCityInfo();
    },

    issuecontent () { //点击搜索
      this.resdata = []
      this.pageNumber = 0;
      this.onLoad();
      this.$forceUpdate();
    },
    select () { //打开选择城市
      this.show = true;
    },
    cell (e) { //选择城市
      this.current = e
      this.show = false;
      this.resdata = []
      this.pageNumber = 0;
      this.onLoad()
      this.$forceUpdate();
      // console.log(e)
      // console.log(this.chengshi)
    },
    popularCs (e) { //选择热门城市
      this.current = e
      this.show = false;
      // console.log(e)
      this.resdata = []
      this.pageNumber = 0;
      this.onLoad()
      this.$forceUpdate();
    },
    onClickLeft () { //关闭选择城市
      this.show = false;
    },
    onSearch (value) { //搜索
      // console.log(value);
      // console.log(this.issue_content)
      this.resdata = []
      this.pageNumber = 0;
      this.onLoad();
      this.$forceUpdate();
    },
    // 筛选
    changeabout (value) {
      this.resdata = []
      this.pageNumber = 0;
      this.onLoad();
      this.$forceUpdate();
      // console.log(value);
      // console.log(this.value1)
    },

    // // 确定选择城市
    // areaconfirm(val) {
    //   this.show = false;
    //   this.popup_city = val[1].name
    //   this.pageNumber = 0
    //   this.onLoad() //我这里必须要加这个吗？
    //   // this.pageNumber--;
    //   // this.$set(this.onLoad, "City", this.popup_city);
    //   this.$forceUpdate();
    //   // console.log(this.$set(this.onLoad))

    // },

    routersoeciakty (resSN) {
      // this.$router.push('/specialty');
      this.$router.push({ //跳转详情
        path: "/specialty/Specialtydetails",
        query: {
          resSN: resSN,
        }
      })
    },
    onLoad () { //特产列表
      // console.log(1)
      setTimeout(() => {
        let data = {
          PageNo: this.pageNumber + 1,
          Category: 6,
          City: this.popup_city, //城市
          Name: this.issue_content, //搜索
          SortType: this.value1, //排序类型

        }

        resourceList(data).then(res => {
          console.log(res)
          this.PageCount = res.PageCount

          if (res.List.length > 0) {
            this.resdata = this.resdata.concat(res.List);
          } else {
            this.resdata = res.List
          }
          this.loading = false;
          this.pageNumber++;
          if (this.pageNumber >= this.PageCount) {
            this.finished = true;
          }
        });
      }, 500)

    },
  },
  watch: {
    isDisabled (val, oldVal) {
      console.log(val)
      if (val == true) {
        this.result = []
        this.result = ['0']
      }
    }
    //
  }
}
</script>
<style lang="scss">
.about {
  background: white;

  .search {
    width: 90%;
    margin: 0 auto;
    display: flex;
    background: white;
    height: 40px;
    border: 1px solid #00cba6;
    border-radius: 30px;

    .search_cs {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 90px;

      .van-icon {
        font-size: 14px !important;
        margin-left: 5px;
      }
    }

    .search_in {
      display: flex;
      align-items: center;
      width: 60%;

      .van-search {
        padding: 0 !important;
        background: #ffffff;

        .van-search__content {
          background: none;

          .van-cell {
            border-left: 1px solid rgb(225, 225, 225);
            padding: 0px 0px 0px 10px;
            background: none;

            input {
              background: none;
            }
          }
        }
      }
    }
  }

  .current {
    display: flex;
    padding: 0.625rem 1rem;
    line-height: 2rem;
    font-size: 1.125rem;
    background: #ffffff;
    justify-content: space-between;
    color: #999999;

    .current_box {
      width: 50%;
      display: flex;
      justify-content: space-around;
    }
  }

  .popular {
    .popular_p {
      padding: 10px 16px;
      background: #f5f5f5;
      font-size: 1.1rem;
    }

    .popular_cs {
      width: 80px;
      height: 30px;
      margin: 0.625rem 0.625rem;
      border-radius: 1.875rem;
      border: 1px solid #e4e4e4;
      display: flex;
      font-size: 1rem;
      align-items: center;
      justify-content: center;
    }
  }

  .van-index-bar {
    color: #999999 !important;

    .van-index-anchor {
      background: #f5f5f5;
      color: #999999 !important;
      font-weight: 600;
    }

    .van-cell {
      color: #999999 !important;
    }
  }

  .van-popup {
    // top: 0;
    // transform:translate3d(0,0%,0) !important;
    .van-nav-bar {
      .van-nav-bar__left {
        .van-icon {
          font-size: 22px;
          color: white !important;
        }
      }
    }
  }

  // .searche {
  //   width: 100%;
  //   display: flex;
  //   justify-content: center;
  //   height: 80px;
  //   align-items: center;
  //   background: #68c5ba;

  //   .search_search {
  //     width: 88%;
  //     display: flex;
  //     background: white;
  //     border-radius: 5px;
  //     overflow: hidden;

  //     .search_left {
  //       width: 30%;
  //       height: 100%;
  //       text-align: center;
  //       border-right: 1px solid #ececec;

  //       // margin-left: 15px;
  //       .van-button {
  //         color: #828282;
  //         height: 100%;
  //         background: white;
  //         border: none;
  //         padding: 0 0 !important;
  //       }
  //     }

  //     .search_rihtg {
  //       display: flex;
  //       justify-content: center;
  //       align-items: center;

  //       .van-search {
  //         padding: 0 0;
  //         background: white;

  //         .van-cell {
  //           padding: 0 0;
  //           background: white;

  //           .van-field__control {
  //             width: 90% !important;
  //           }
  //         }
  //       }
  //     }

  //   }
  // }
  .sort {
    position: fixed;
    top: 60px;
    width: 100%;
  }

  .about-box {
    width: 100%;
    display: flex;
    // justify-content: space-around;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;

    .van-list__finished-text {
      width: 100% !important;
    }

    // flex-direction: column;
    .content-piece {
      width: 46%;
      min-height: 17.75rem;
      background: #f6f6f6;
      color: #aeaeae;
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-left: 0.625rem;
      margin-top: 0.625rem;

      .piece-img {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 190px;

        // background: red;
        img {
          width: 90%;
        }
      }

      .piece-size {
        width: 90%;
        height: 4rem;
        overflow: hidden;
        font-size: 14px;
        color: #8f8f8f;
      }

      .piece-money {
        display: flex;
        font-size: 14px;
        width: 90%;
        justify-content: space-between;
      }
    }
  }
}
</style>
